package com.itheima.service.impl;

import com.itheima.mapper.MobileSetmealMapper;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetmealServiceImpl implements SetmealService {
    @Autowired
    private MobileSetmealMapper setmealMapper;

    /**
     * 获取所有套餐
     * @return
     */
    @Override
    public List<Setmeal> getSetmeal() {
        List<Setmeal> list = setmealMapper.getSetmeal();
        return list;
    }

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Override
    public Setmeal findById(Integer id) {
        Setmeal setmeal = setmealMapper.findById(id);
        setmeal.setCheckGroups(setmealMapper.getCheckGroupsBySetmealId(id));
        List<CheckGroup> checkGroups = setmeal.getCheckGroups();
        for (CheckGroup checkGroup : checkGroups) {
            checkGroup.setCheckItems(setmealMapper.getCheckItemsByCheckGroupId(checkGroup.getId()));
        }
        return setmeal;
    }
}
